<template>
  <div class="login-wrap">
    <div class="model"></div>
    <div class="ms-title">国朗项目管理 </div>
    <div class="ms-login">
      <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px" class="demo-ruleForm login-container">
        <!--<h3 class="title">系统登录</h3>-->
        <el-form-item prop="userName">
          <el-input type="text" v-model="ruleForm2.userName" auto-complete="off" placeholder="账号"></el-input>
        </el-form-item>
        <el-form-item prop="userPwd">
          <el-input type="password" v-model="ruleForm2.userPwd" auto-complete="off" placeholder="密码"></el-input>
        </el-form-item>
        <el-checkbox v-model="checked" checked class="remember">记住密码</el-checkbox>
        <el-form-item style="width:100%;">
          <el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit2" :loading="logining">登录</el-button>
          <!--<el-button @click.native.prevent="handleReset2">重置</el-button>-->
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
    import insurance from '../api/insurance';
    import { requestLogin,requestLogin1 } from '../api/api';
  export default {
    data() {
      return {
        logining: false,
        ruleForm2: {
            userName: '',
            userPwd: ''
        },
        rules2: {
            userName: [
            { required: true, message: '请输入账号', trigger: 'blur' },
          ],
            userPwd: [
            { required: true, message: '请输入密码', trigger: 'blur' },
          ]
        },
        checked: true
      };
    },
    methods: {
      handleReset2() {
        this.$refs.ruleForm2.resetFields();
      },
      handleSubmit2(ev) {
        var that = this;
          that.$refs.ruleForm2.validate((valid) => {
          if (valid) {
              that.logining = true;
              var data = JSON.stringify({ usrname: that.ruleForm2.userName, pwd: that.ruleForm2.userPwd });

              $.ajax(insurance.posturl+"user/login",{
                  'data': data,
                  headers: {'Content-Type': 'application/json;charset=UTF-8'},
                  // headers: {'Content-Type': 'multipart/form-data'},

                  'type': 'POST',
                  success:function (res) {
                      res = JSON.parse(res);
                      if(res.isSuccess){
                          that.$message({ message: '登录成功',type: 'success'});
                          var d = res.Content;
                          sessionStorage.setItem('user', d);
                          sessionStorage.setItem('isRembers', that.checked);

                          that.$router.push({ path: '/projectNO' });
                      }else{
                          that.$message({ message: '登录失败',type: 'success'});
                      }
                      that.logining = false;
                  }
              });
          } else {
            return false;
          }
        });
      }
    },
    mounted(){
        var url = window.location.href;
        var url1 = url.split(':')[1];
        localStorage.setItem('ipUrl',url1);
        console.log('获取'+url1);

        if (sessionStorage.getItem('user')) {
            this.ruleForm2.userName = JSON.parse(sessionStorage.getItem('user')).usrname;
            this.ruleForm2.userPwd = JSON.parse(sessionStorage.getItem('user')).pwd;
        }
    }
  }
</script>
<style src="../../static/css/datasource.css"></style>
@import url("//unpkg.com/element-ui/lib/theme-default/index.css");
<style lang="scss" scoped>
  .ms-login[data-v-83e7217a]{height: 223px;}
  .ms-login input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill {
    background-color: red !important;
    background-image: none !important;
    color: rgb(0, 0, 0) !important;
  }
  .login-wrap{
    position: relative;
    background-repeat: no-repeat;
    width:100%;
    height:100%;
    background-image: url("../../static/img/bg1.jpg");
    background-size: 100% 100%;
  }
  .ms-title{
    position: absolute;
    top:50%;
    width:100%;
    margin-top: -230px;
    text-align: center;
    font-size:30px;
    color: #fff;

  }
  .ms-login{
    position: absolute;
    left:50%;
    top:50%;
    width:300px;
    height:185px;
    margin:-150px 0 0 -190px;
    padding:40px;
    border-radius: 5px;
    background: #fff;
  }
  .login-btn{
    text-align: center;
  }
  .login-btn button{
    width:100%;
    height:36px;
  }
</style>